from time import sleep

from selenium.webdriver.common.by import By

import page
from base.base import Base
from tool.get_log import GetLogger

log = GetLogger.get_log()


class PageConversation(Base):

    def page_init(self):
        log.info('正在进行page初始化操作')
        size = self.driver.get_window_size()
        self.base_find_element((By.XPATH, "//*[@text='发现']"))
        self.driver.swipe(size['width'] * 0.5, size['height'] * 0.4, size['width'] * 0.5, size['height'] * 0.9)
        self.base_click_element(page.init_xcx_name)
        sleep(5)
        self.driver.switch_to.context(self.driver.contexts[-1])
        # self.base_click_element(page.fp_signin_close)
        try:
            log.info("正在跳过首页签到弹窗")
            self.base_click_element(page.fp_signin_close)
            log.info("首页签到弹窗已关闭")
        except:
            log.info("未找到首页弹窗")
            pass

    def page_conversation_back_url(self):
        # pass
        for i in range(3):
            sleep(5)
            try:
                self.base_find_element(page.chat_baping_btn)
                break
            except:
                self.driver.press_keycode(4)

    def page_conversation_entrance(self):
        self.base_scroll_element_into_view_js(page.fp_chat_group_tab, istop='false')
        self.base_click_element(page.fp_chat_group_tab)
        self.base_scroll_element_into_view_js(page.fp_chat_group, istop='false')
        while True:
            self.base_click_element(page.fp_chat_group)
            if self.base_if_element_exist(page.chat_baping_btn, timeout=5):
                break
        try:
            self.base_click_element(page.chat_desk_num_close, timeout=5)
        except:
            pass

    def page_conversation_click_ad(self):
        self.base_click_element(page.chat_banner_ad)

    def page_conversation_ad_assert(self):
        return self.base_if_element_exist(page.pay_manghe_assert)

    def page_conversation_click_rank(self):
        self.base_click_element(page.chat_rank)

    def page_conversation_rank_assert(self):
        return self.base_if_element_exist(page.rank_title)

    def page_conversation_click_vip_store(self):
        self.base_click_element(page.chat_vip_mall)

    def page_conversation_vip_store_assert(self):
        return self.base_if_element_exist(page.vip_open_button)

    def page_conversation_click_group_member(self):
        self.base_click_element(page.chat_group_people)

    def page_conversation_group_assert(self):
        return self.base_if_element_exist(page.group_people_list)

    def page_conversation_click_game(self):
        self.base_click_element(page.chat_game)

    def page_conversation_game_assert(self):
        return self.base_if_element_exist(page.game_list)

    def page_conversation_click_hongbao(self):
        self.base_click_element(page.chat_hongbao)

    def page_conversation_hongbao_assert(self):
        return self.base_if_element_exist(page.hongbao_amount)

    def page_conversation_click_vip_coming(self):
        self.base_click_element(page.chat_vip_coming)

    def page_conversation_vip_coming_assert(self):
        return self.base_if_element_exist(page.chat_vip_tanchuang_close)

    def page_conversation_close_vip_coming_tanchuang(self):
        self.base_click_element(page.chat_vip_tanchuang_close)

    def page_conversation_send_message(self, msg):
        self.base_input_value(page.chat_message_input_area, value=msg)
        self.base_click_element(page.chat_message_send_btn)

    def page_coversation_get_send_message(self):
        return self.base_get_element_text(page.chat_message_assert)
